package zhy.UseViewGroupCustomPullRefresh;

import zhy.UseViewGroupCustomPullRefresh.PullRefreshViewGroup.onRefreshingCallback;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;

public class SampleNoScrollActivity1  extends Activity{

	PullRefreshViewGroup group;
	ImageView img;
	int[] pics={R.drawable.ic_launcher,R.drawable.a1,R.drawable.a2,R.drawable.a3};
	Handler handler;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		handler=new Handler();
		setContentView(R.layout.activity1);
		group=(PullRefreshViewGroup)findViewById(R.id.group);
		img=(ImageView)findViewById(R.id.img);
		
		
		group.setRefreshingCallBack(new onRefreshingCallback(){
			@Override
			public void onRefreshing() {
				load();
			}} );
		group.init();
	}
	
	void load()
	{
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				//System.out.println("load start");
				
				try {
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				handler.post(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						int i=(int)(pics.length*Math.random());
						img.setImageResource(pics[i]);
						//System.out.println("pic:"+i);
						group.onRefreshComplete();
					}
				});
				
			}
		}).start();
	}
}
